﻿using System;
using System.Configuration;
using NHibernate;
using NHibernate.Cfg;
using FluentNHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;

namespace Data.Database
{
    public class SessionFactoryBuilder<T>
    {
        public static ISessionFactory CreateSessionFactory()
        {
            try
            {
                string connString = ConfigurationManager.ConnectionStrings["Default"].ToString().Trim();
                
                ISessionFactory sessionFactory = Fluently.Configure().Database(MsSqlConfiguration.MsSql2008
                .ConnectionString(connString)).Mappings(m => m.FluentMappings.AddFromAssemblyOf<T>())
                .BuildSessionFactory();

                return sessionFactory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
